home *** CD-ROM | disk | FTP | other *** search
- ; Example 1: Basics
-
- ; This file contains a fairly simple program written in the
- ; assembly language of xComputer. It illustrates a few basic
- ; assembly language instructions and the format of assembly
- ; language programs. (Note that a semicolon (;) and anthing
- ; that follows it on a line is a comment.)
-
- ; This and other example files illustrate the functionality
- ; of xComputer. They do not tell you everything you need to
- ; know to use the xComputer program. For that, you should read
- ; the file "READ ME (with instructions!)". That file also
- ; includes a complete specification of the assembly language
- ; of xComputer.
-
- ; To run this program, open it with the xComputer program.
- ; Make sure the program is in the frontmost window on the
- ; screen. Choose the command "Load Example 1 - Basics" from
- ; the Assembler menu. Make sure that the PC register contains
- ; the number 0, which gives the starting address of the program
- ; in memory. (Use the "Set PC=0" command from the Assembler
- ; menu, if necessary.) Then use the Run command from the
- ; Assembly menu to start the program, or, equivalently,
- ; click on the checkbox labled "Stop-Clock" in the xComputer
- ; window.
-
- ; This program computes the sum of a list of numbers. The list
- ; can contain only non-zero numbers. A zero marks the end of
- ; the list.
-
-
-
- lod-c 0 ; Load the constant 0 into the AC; this
- ; will be the starting value of the sum.
- sto sum ; Store the contents of the AC into
- ; location "sum". "Sum" is a label
- ; that is used to refer to some memory
- ; location. (It is defined later in the
- ; program by using it to label one of
- ; the lines in the program.)
- lod-c numList ; Load the constant "numList" into AC
- sto num ; and then copy it into location "num".
-
- doSum: lod-i num ; "Load-indirect from num", that is, get
- ; the contents of location "num", and
- ; use THAT number as the location of the
- ; number to be loaded into the AC. In
- ; this case, one of the numbers in the
- ; list is loaded. Note that "doSum"
- ; is a label for this instruction.
- jmz done ; If the number in the AC is zero, then
- ; jump to location "done". (The zero
- ; marks the end of the list of numbers.)
- add sum ; Otherwise, add the number in location
- ; "sum" to the AC
- sto sum ; and put the answer back in "sum".
- lod num ; Now, get the number from "num",
- inc ; add 1 to it,
- sto num ; and put the answer back in "num".
- ; (This gets us ready to access the
- ; next item in the list.)
- jmp doSum ; Jump back to location "doSum", which
- ; is therefore the starting point of
- ; a loop.
- done: hlt ; Halt; the program jumps to this point
- ; when the program is done.
-
- num: data ; Allocate a memory location to hold data
- ; and set the label "num" to refer
- ; to that memory location. ("Data" is
- ; not an instruction, just a placeholder
- ; that tells the assembler to reserve
- ; a memory location.)
- sum: data ; Allocate a memory location named "sum";
- ; This location, which will be location
- ; number 14 when the program is loaded,
- ; will hold the answer when the
- ; program ends.
-
- numList: ; A label that names the starting point for
- ; the list of numbers to be added. (Note that
- ; a label does not have to be on the same line
- ; with the item it labels.)
- 27 ; The list of numbers to be added. Note that
- 53 ; when a number is encountered as a line in
- 107 ; a program, that number is simply loaded
- -22 ; into a memory location. Thus, these numbers
- 67 ; will occupy successive memory locations
- -232 ; starting at location 15. Of course, the
- 123 ; program will work for any list of numbers.
- 1 ; (Note: If you load this program and then
- 272 ; set the Memory Display Option to "Assembly
- -13 ; Language", some of these numbers will look
- -12 ; sort of funny, since they do not represent
- 100 ; legal assembly language instructions.)
- 0 ; A zero marks end of the list of numbers
- ; to be added.